package com.alan.api.config;

import com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.BeanValidationPostProcessor;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

/**
 * Created by Alan on 17-10-13
 */
@Configuration
public class InitBeanConfig {

    /**
     * 参数验证
     * @return
     */
//    @Bean
//    public ParamValidateBean paramValidateBean(){
//        ParamValidateBean paramValidateBean = new ParamValidateBean();
//        paramValidateBean.setAutoBack(true);
//        return paramValidateBean;
//    }

    /**
     * 方法级验证 要在方法或类上加 @Validated 注解
     * @return
     */
    @Bean
    public MethodValidationPostProcessor methodValidationPostProcessor(){
        return new MethodValidationPostProcessor();
    }

    /**
     * 实体类验证 @Valid BindingResult
     * @return
     */
    @Bean
    public BeanValidationPostProcessor beanValidationPostProcessor(){
        return new BeanValidationPostProcessor();
    }

    /**
     * 乐观锁配置（无强制 可以不传version）
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        OptimisticLockerInterceptor optimisticLockerInterceptor = new OptimisticLockerInterceptor();
        return optimisticLockerInterceptor;
    }

}
